const AreaService = require('../services/area.service')

const areaService = new AreaService()

class UserController {
  async findAll (ctx, next) {
    const query = ctx.request.query
    const data = await areaService.findAll(query)
    ctx.response.body = data
  }
  async findOne (ctx, next) {
    const id = ctx.request.params.id
    const data = await areaService.findOne(id)
    ctx.response.body = data[0]
  }
  async updateOne (ctx, next) {
    const id = ctx.request.params.id
    const body = ctx.request.body
    const data = await areaService.updateOne(id, body)
    ctx.response.body = data
  }
  async deleteOne (ctx, next) {
    const id = ctx.request.params.id
    const data = await areaService.deleteOne(id)
    ctx.response.body = data
  }
  async addOne (ctx) {
    const body = ctx.request.body
    body.owner = ctx.state.user._id
    const data = await areaService.addOne(body)
    ctx.response.body = data
  }
}

module.exports = UserController